package utils;

import static controller.view.NLConstants.REF_BASE;

import java.text.SimpleDateFormat;
import java.util.Date;

import model.vo.Position;
import controller.NLSimulator;
import estimation.impl.MediaMovelJ3;
import estimation.impl.MediaMovelJ5;
import estimation.impl.MediaMovelJ7;
import estimation.impl.MinimosQuadradosJ3;
import estimation.impl.MinimosQuadradosJ5;
import estimation.impl.MinimosQuadradosJ7;

public class NoLimeUtils {

	public static String formatTime(long time) {		
		Date now = new Date(time);
		SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
		return format.format(now);
	}
	
	public static double subtract(Position pos1,Position pos2){
		double x=pos2.getX()-pos1.getX();
		double y=pos2.getY()-pos1.getY();
		return Math.abs(x+y);
	}
	
	public static String format(String value){
		
		int index=value.indexOf('.');
		
		if(index==-1){
			return "NaN";
		}
		
		return value.substring(0, index+2);
		
	}
	
	public static String format(double value){
		return format(value+"");
	}
	
	public static void predictMQVerbose(NLSimulator m, int steps) {

		String MQ3 = NoLimeUtils.format(m.Predict(MinimosQuadradosJ3.class,
				REF_BASE * steps));
		String MQ5 = NoLimeUtils.format(m.Predict(MinimosQuadradosJ5.class,
				REF_BASE * steps));
		String MQ7 = NoLimeUtils.format(m.Predict(MinimosQuadradosJ7.class,
				REF_BASE * steps));
		
		System.out.print(MQ3 + ",");
		System.out.print(MQ5 + ",");
		System.out.print(MQ7 + ",");

	}
	
	public static void predictMMVerbose(NLSimulator m, int steps) {

		String MQ3 = NoLimeUtils.format(m.Predict(MediaMovelJ3.class,
				REF_BASE * steps));
		String MQ5 = NoLimeUtils.format(m.Predict(MediaMovelJ5.class,
				REF_BASE * steps));
		String MQ7 = NoLimeUtils.format(m.Predict(MediaMovelJ7.class,
				REF_BASE * steps));
		
		System.out.print(MQ3 + ",");
		System.out.print(MQ5 + ",");
		System.out.print(MQ7 + ",");

	}
	
	public static void predictMMXMQVerbose(NLSimulator m, int steps) {

		String MQ3 = NoLimeUtils.format(m.Predict(MediaMovelJ7.class,
				REF_BASE * steps));
		String MQ5 = NoLimeUtils.format(m.Predict(MinimosQuadradosJ3.class,
				REF_BASE * steps));
		
		System.out.print(MQ3 + ",");
		System.out.print(MQ5 + ",");		

	}

}
